/**
* @Title: XmlPerson.java
* @Package com.taxsearch.util
* @Description: TODO(用一句话描述该文件做什么)
* @author STIVEN
* @date 2018年9月7日
* @version V1.0
*/
package com.taxsearch.util;

import java.util.HashMap;
import java.util.Map;

import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

/**
* @ClassName: XmlPerson
* @Description: TODO(OCR XML解析)
* @author STIVEN
* @date 2018年9月7日
*
*/

public class XmlParse {
	/**
	 * 
	* @Title: toReadCardxml
	* @Description: TODO(身份证件二代证XML解析)
	* @param @param str
	* @param @return
	* @param @throws DocumentException    参数   XMLStr 传入XML字符串串
	* @return Map<String,String>    返回类型
	 */
	public Map<String,String> toReadCardxml(String XMLStr) throws DocumentException {
		// 将xml格式字符串转化为DOM对象
		org.dom4j.Document document = DocumentHelper.parseText(XMLStr.substring(0, XMLStr.length()-4));
		// 获取根结点对象
		Element rootElement = document.getRootElement();
		Element message= rootElement.element("message");
		Element status= message.element("status");//状态
		Element value= message.element("value");//状态描述
		Element cardsinfo= rootElement.element("cardsinfo");
		if(cardsinfo == null){
			return null;
		}
		Element card= cardsinfo.element("card");//
		Map<String,String> cardMap=new HashMap<String,String>();
		cardMap.put("status", status.getText());
		cardMap.put("value", value.getText());
		cardMap.put("reserve", card.selectSingleNode("item[@desc='保留']").getText());
		cardMap.put("name", card.selectSingleNode("item[@desc='姓名']").getText());
		cardMap.put("sex", card.selectSingleNode("item[@desc='性别']").getText());
		cardMap.put("nation", card.selectSingleNode("item[@desc='民族']").getText());
		cardMap.put("birth", card.selectSingleNode("item[@desc='出生']").getText());
		cardMap.put("addr", card.selectSingleNode("item[@desc='住址']").getText());
		cardMap.put("CardNO", card.selectSingleNode("item[@desc='公民身份号码']").getText());
		cardMap.put("Photo", card.selectSingleNode("item[@desc='头像']").getText());
		return cardMap;
	}
	/**
	 * 
	* @Title: toReadCardxml
	* @Description: TODO(护照XML解析包含境内外)
	* @param @param XMLStr
	* @param @return
	* @param @throws DocumentException    参数
	* @return Map<String,String>    返回类型
	 */
	public Map<String,String> toReadPassportXml(String XMLStr) throws DocumentException {
		// 将xml格式字符串转化为DOM对象
		org.dom4j.Document document = DocumentHelper.parseText(XMLStr.substring(0, XMLStr.length()-4));
		// 获取根结点对象
		Element rootElement = document.getRootElement();
		Element message= rootElement.element("message");
		Element status= message.element("status");//状态
		Element value= message.element("value");//状态描述
		Element cardsinfo= rootElement.element("cardsinfo");
		if(cardsinfo == null){
			return null;
		}
		Element card= cardsinfo.element("card");//
		Map<String,String> cardMap=new HashMap<String,String>();
		cardMap.put("status", status.getText());
		cardMap.put("value", value.getText());
		cardMap.put("passportType", card.selectSingleNode("item[@desc='护照类型']").getText());
		cardMap.put("passportNumber", card.selectSingleNode("item[@desc='护照号码MRZ']").getText());
		cardMap.put("nationalName", card.selectSingleNode("item[@desc='本国姓名']").getText());
		cardMap.put("englishName", card.selectSingleNode("item[@desc='英文姓名']").getText());
		cardMap.put("sex", card.selectSingleNode("item[@desc='性别']").getText());
		cardMap.put("dateBrith", card.selectSingleNode("item[@desc='出生日期']").getText());
		cardMap.put("vldDate", card.selectSingleNode("item[@desc='有效期至']").getText());
		cardMap.put("signContr", card.selectSingleNode("item[@desc='签发国代码']").getText());
		cardMap.put("lastName", card.selectSingleNode("item[@desc='英文姓']").getText());
		cardMap.put("firstName", card.selectSingleNode("item[@desc='英文名']").getText());
		cardMap.put("givenNames", card.selectSingleNode("item[@desc='签发国代码']").getText());
		cardMap.put("MRZ1", card.selectSingleNode("item[@desc='MRZ1']").getText());
		cardMap.put("MRZ2", card.selectSingleNode("item[@desc='MRZ2']").getText());
		cardMap.put("nationalityNUM", card.selectSingleNode("item[@desc='持证人国籍代码']").getText());
		cardMap.put("passportNumber", card.selectSingleNode("item[@desc='护照号码']").getText());
		cardMap.put("birthAddr", card.selectSingleNode("item[@desc='出生地点']").getText());
		cardMap.put("placeIssue", card.selectSingleNode("item[@desc='签发地点']").getText());
		cardMap.put("DateIssue", card.selectSingleNode("item[@desc='签发日期']").getText());
		cardMap.put("RFIDMRZ", card.selectSingleNode("item[@desc='RFID MRZ']").getText());
		cardMap.put("OCRMRZ", card.selectSingleNode("item[@desc='OCR MRZ']").getText());
		cardMap.put("RFIDMRZ", card.selectSingleNode("item[@desc='RFID MRZ']").getText());
		cardMap.put("birthAddrPinyin", card.selectSingleNode("item[@desc='出生地点拼音']").getText());
		cardMap.put("placePinyin", card.selectSingleNode("item[@desc='签发地点拼音']").getText());
		cardMap.put("cardNumber", card.selectSingleNode("item[@desc='身份证号码']").getText());
		cardMap.put("nationalNamePinyinOCR", card.selectSingleNode("item[@desc='本国姓名拼音OCR']").getText());
		cardMap.put("nationacodeOCR", card.selectSingleNode("item[@desc='持证人国籍代码OCR']").getText());
		cardMap.put("cardIDOCR", card.selectSingleNode("item[@desc='身份证号码OCR']").getText());
		cardMap.put("birthOCR", card.selectSingleNode("item[@desc='出生日期OCR']").getText());
		cardMap.put("validOCR", card.selectSingleNode("item[@desc='有效期至OCR']").getText());
		cardMap.put("signOCR", card.selectSingleNode("item[@desc='签发机关OCR']").getText());
		cardMap.put("nationSur", card.selectSingleNode("item[@desc='本国姓']").getText());
		cardMap.put("nationGivenN", card.selectSingleNode("item[@desc='本国名']").getText());
		cardMap.put("Height", card.selectSingleNode("item[@desc='身高']").getText());
		cardMap.put("photo", card.selectSingleNode("item[@desc='头像']").getText());
		return cardMap;
	}
/**
 * 
* @Title: toReadPlicCardxml
* @Description: TODO(军官证解析)
* @param @param XMLStr
* @param @return
* @param @throws DocumentException    参数
* @return Map<String,String>    返回类型
 */
	public Map<String,String> toReadPlicCardxml(String XMLStr) throws DocumentException {
		// 将xml格式字符串转化为DOM对象
		org.dom4j.Document document = DocumentHelper.parseText(XMLStr.substring(0, XMLStr.length()-4));
		// 获取根结点对象
		Element rootElement = document.getRootElement();
		Element message= rootElement.element("message");
		Element status= message.element("status");//状态
		Element value= message.element("value");//状态描述
		Element cardsinfo= rootElement.element("cardsinfo");
		if(cardsinfo == null){
			return null;
		}
		Element card= cardsinfo.element("card");//
		Map<String,String> cardMap=new HashMap<String,String>();
		cardMap.put("status", status.getText());
		cardMap.put("value", value.getText());
		cardMap.put("reserve", card.selectSingleNode("item[@desc='保留']").getText());
		cardMap.put("name", card.selectSingleNode("item[@desc='姓名']").getText());
		cardMap.put("CardNO", card.selectSingleNode("item[@desc='编号']").getText());
		cardMap.put("birth", card.selectSingleNode("item[@desc='出生年月']").getText());
		cardMap.put("sex", card.selectSingleNode("item[@desc='性别']").getText());
		cardMap.put("addr", card.selectSingleNode("item[@desc='籍贯']").getText());
		cardMap.put("nation", card.selectSingleNode("item[@desc='民族']").getText());
		cardMap.put("Photo", card.selectSingleNode("item[@desc='头像']").getText());
		return cardMap;
	}

		public Map<String,String> toHukouBookPxml(String XMLStr) throws DocumentException {
			// 将xml格式字符串转化为DOM对象
			org.dom4j.Document document = DocumentHelper.parseText(XMLStr.substring(0, XMLStr.length()-4));
			// 获取根结点对象
			Element rootElement = document.getRootElement();
			Element message= rootElement.element("message");
			Element status= message.element("status");//状态
			Element value= message.element("value");//状态描述
			Element cardsinfo= rootElement.element("cardsinfo");
			if(cardsinfo == null){
				return null;
			}
			Element card= cardsinfo.element("card");//
			Map<String,String> cardMap=new HashMap<String,String>();
			cardMap.put("status", status.getText());
			cardMap.put("value", value.getText());
			cardMap.put("reserve", card.selectSingleNode("item[@desc='保留']").getText());
			cardMap.put("name", card.selectSingleNode("item[@desc='姓名']").getText());
			cardMap.put("CardNO", card.selectSingleNode("item[@desc='公民身份证件编号']").getText());
			cardMap.put("birth", card.selectSingleNode("item[@desc='出生日期']").getText());
			cardMap.put("sex", card.selectSingleNode("item[@desc='性别']").getText());
			cardMap.put("nation", card.selectSingleNode("item[@desc='民族']").getText());
			cardMap.put("Photo", card.selectSingleNode("item[@desc='头像']").getText());
			return cardMap;
		}
}
